

package com.jinkaimen.kqb.ui.activity.h5toapp;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.jinkaimen.kqb.R;
import com.jinkaimen.kqb.bean.hss.PaymentMethodBean;
import com.jinkaimen.kqb.manager.ApiManager;
import com.jinkaimen.kqb.ui.adapter.PaymentMethodAdapter;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Response;


public class SelectPaymentMethodActivity extends BaseActivity {
    private ListView mListview;
    private String amount;
    private long ordernumber;
    private int type;
    private ArrayList<PaymentMethodBean> paymentMethodBeanArrayList = new ArrayList<>();
    private ArrayList<PaymentMethodBean> paymentMethodBeanList = new ArrayList<>();
    private PaymentMethodAdapter paymentMethodAdapter;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("选择收款方式");
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        amount = callIntent.getStringExtra("amount");
        ordernumber = callIntent.getLongExtra("ordernumber", -1);
        type = callIntent.getIntExtra("type", -1);
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_select_payment_method;
    }

    @Override
    protected void initChildView() {
        mListview = (ListView) findViewById(R.id.listview);
        View footView = View.inflate(this, R.layout.list_foot_view_select_paument_method, null);
        paymentMethodAdapter = new PaymentMethodAdapter(this, paymentMethodBeanList);
        mListview.addFooterView(footView);
        mListview.setAdapter(paymentMethodAdapter);
    }

    @Override
    protected void initChildData() {
        ApiManager.getApi().payMenthodList(
                "HSS001041"
        ).enqueue(new NetCallBack<ArrayList<PaymentMethodBean>>() {
            @Override
            protected void onSuccess(Call<ArrayList<PaymentMethodBean>> call, Response<ArrayList<PaymentMethodBean>> response) {
                if (response != null) {
                    paymentMethodBeanArrayList = response.body();
                    if (paymentMethodBeanArrayList != null && paymentMethodBeanArrayList.size() >= 1) {
                        for (int i = 0; i < paymentMethodBeanArrayList.size(); i++) {
                            if (type == 1) {
                                if (paymentMethodBeanArrayList.get(i).payMethodCode != 3 && paymentMethodBeanArrayList.get(i).payMethodCode != 5) {
                                    paymentMethodBeanList.add(paymentMethodBeanArrayList.get(i));
                                }
                            } else if (type == 2) {
                                if (paymentMethodBeanArrayList.get(i).payMethodCode == 3) {
                                    paymentMethodBeanList.add(paymentMethodBeanArrayList.get(i));
                                }
                            } else if (type == 3) {
                                if (paymentMethodBeanArrayList.get(i).payMethodCode == 5) {
                                    paymentMethodBeanList.add(paymentMethodBeanArrayList.get(i));
                                }
                            }
                        }
                        paymentMethodAdapter.notifyDataSetChanged();
                    }
                }
            }

        });

    }

    @Override
    protected void setChildViewListener() {
        mListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Bundle bundle = new Bundle();
                bundle.putLong("ordernumber", ordernumber);
                bundle.putInt("channel", paymentMethodBeanList.get(i).channel);
                ActivityUtils.startActivityAndFinish(SelectPaymentMethodActivity.this, QrcodeShowActivity.class, bundle);
            }
        });
    }


}
